#ifndef __WEBPAGEQUERY_HH
#define __WEBPAGEQUERY_HH
#include "../SplitTool.hh"
#include "../Configuration.hh"
#include "tinyxml2.h"
#include "WebPage.hh"

#include <string>
#include <set>
#include <unordered_map>
#include <queue>

using std::string;
using std::set;
using std::unordered_map;
using std::pair;
using std::priority_queue;


class MyCompare1
{
public:
    bool operator()(const pair<int, double>& a, const pair<int, double>& b) const
    {
        return a.second > b.second;
    }
    
};

class WebPageQuery
{
public:
    WebPageQuery(SplitTool* tool);
    // 
    vector<string> doQuery(const string& query);
    void loadLibrary();
    vector<double> getQueryWordsWeightVector(const vector<string>& queryWords);
    bool executeQuery(const vector<string>& queryWords, vector<pair<int, vector<double>>>& resultVec);
    string createJson(vector<int>& docidVec, const vector<string>& queryWords);
    string returnNoAnswer();
    void clear();
    vector<int> CosSort(vector<pair<int, vector<double>>>& resultVec, const vector<string> &queryWords);
    void loadPage();
private:
    SplitTool* _tool;
    unordered_map<int, WebPage> _pageLib;
    unordered_map<int, pair<size_t, size_t>> _offsetLib;
    unordered_map<string, set<pair<int, double>>> _invertIndexTable;
};



#endif